package com.bo.atomicity;

/**
 * @Author: gpb
 * @Date: 2024/7/28 10:46
 * @Description:
 */
public class IThreadLocal {
    static ThreadLocal tl1 = new ThreadLocal();
    static ThreadLocal tl2 = new ThreadLocal();

    public static void main(String[] args) {
        tl1.set("main->123");
        tl2.set("main->456");
        Thread t = new Thread(() -> {
            // 是获取不到主线设置的数据的
            System.out.println("线程" + Thread.currentThread().getName() + ",获取tl1数据：" + tl1.get());
            System.out.println("线程" + Thread.currentThread().getName() + ",获取tl2数据：" + tl2.get());
        });
        t.start();
        System.out.println("线程" + Thread.currentThread().getName() + ",获取tl1数据：" + tl1.get());
        System.out.println("线程" + Thread.currentThread().getName() + ",获取tl1数据：" + tl2.get());
    }
}
